<template>
  <div class="login-container">
    <div class="login-page">
      <el-form :model="form" :rules="rules" ref="formRef">
        <el-form-item prop="username">
          <!-- 背景图 -->
          <div class="title-box"></div>
          <el-input v-model="form.username" placeholder="请输入用户名">
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="form.password" placeholder="请输入密码"></el-input>
        </el-form-item>
        <!-- 确认按钮 -->
        <el-form-item>
          <el-button type="primary" @click="doLogin">登录</el-button>
        </el-form-item>
      </el-form>
      <router-link to="/register">去注册</router-link>
    </div>
  </div>
</template>

<script>
export default {
  name: 'login-page',
  data () {
    return {
      form: {
        username: 'hmdrz1',
        password: '123123'
      },
      rules: {
        username: [
          { required: true, message: '用户名不能为空', trigger: 'blur' },
          {
            pattern: /^\w{6,15}$/,
            message: '用户名必须是6-15位的字母、数字',
            trigger: 'blur'
          }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' },
          {
            pattern: /^\w{6,15}$/,
            message: '用户名必须是6-15位的字母、数字',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    async doLogin () {
      await this.$refs.formRef.validate()
      // const res = await authorizations(this.form)
      // console.log(res)
      this.$store.dispatch('user/login', this.form)
    }
  }
}
</script>

<style lang="scss" scoped>
.login-container {
  background: url('http://heimazxk.gitee.io/vue-cms/img/login_bg.09ea0026.jpg')
    50% no-repeat;
  background-size: cover;
  min-height: 100vh;

  .login-page {
    width: 400px;
    height: 270px;
    background-color: #fff;
    padding: 0 30px;
    border-radius: 3px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    box-sizing: border-box;
    .title-box {
      height: 60px;
      background: url('')
        50% no-repeat;
    }
    .el-button {
      width: 100%;
    }
  }
}
</style>
